const { Tab } = require('../../assets/libs/zanui/index');

var app = getApp();
Page(Object.assign({}, Tab, {
  data: {
    isHidden: true,
	  cdnUrl: '',
    devoteseCurrent: {},
    devotesetList: [],
		/* 自定义导航栏参数 */
		loading: false,
		color: '#FFFFFF',
		background: '#02B3BA',
		show: true,
		animated: false,
		back: false,
		title: '发现',
		/* 自定义tabbar */
		list: [
			{
					"pagePath": "/page/index/index",
					"iconPath": "/assets/images/tabbar/index.png",
					"selectedIconPath": "/assets/images/tabbar/index-hl.png",
					"text": "首页"
			},
			{
					"pagePath": "/page/discover/index",
					"iconPath": "/assets/images/tabbar/addon.png",
					"selectedIconPath": "/assets/images/tabbar/addon-hl.png",
					"text": "发现"
			},
			{
					"pagePath": "/page/my/index",
					"iconPath": "/assets/images/tabbar/my.png",
					"selectedIconPath": "/assets/images/tabbar/my-hl.png",
					"text": "我的"
			}
		],
		currentTab: 1,
		
		knowledgelList:[]//分类知识
  },
  tabChange(e) {
	  this.setData({
	  	currentTab: e.detail.index
	  })
  	wx.reLaunch({
  	  url: e.detail.item.pagePath
  	})
  	
  },
  onLoad: function () {
    var that = this;
		that.setData({
			cdnUrl: app.cdnUrl,
		});
		that.knowledgelList();
		that.devotesetList();
  },
	onShow: function(){
		var that = this;
		if (!app.globalData.userInfo) {
		  app.check(that);
		}
	},
	/* 获取绿色贡献值 */
	devotesetList: function (){
		var that = this;
		app.request('/addons/cms/wxapp.recovery/devoteset', {}, function (data, ret) {
		  that.setData({
				devotesetList: data
		  });
		}, function (data, ret) {
		  // app.error(ret.msg);
		});
	},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
	/* 获取分类知识 */
  knowledgelList: function () {
		var that = this;
    app.request('/addons/cms/wxapp.content/knowledge', {}, function (data, ret) {
      that.setData({
				knowledgelList: data
      });
      // typeof cb == 'function' && cb(data);
    }, function (data, ret) {
      // app.error(ret.msg);
    });
  },

  onShareAppMessage: function () {
    return {
      title: '',
      desc: '',
      path: '/page/index/index'
    }
  },
  showMd: function(e) {
      console.log(e);
      //弹出框展示套餐的具体商品，根据data-group得到数组对象，然后再渲染到界面上
      var that = this;
      var offset = e.currentTarget.dataset.index;
      this.setData({
          isHidden: false,//显示模态框，
          devoteseCurrent: that.data.devotesetList[offset],
      })
  },

  hiddenMd: function() {
      this.setData({
          isHidden: true//隐藏模态框
      })
  },
}))
